package com.property.manage.controller.renovation;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.renovation.DepositVo;
import com.property.manage.model.renovation.InspectionVo;
import com.property.manage.service.renovation.DepositService;
import com.property.manage.service.renovation.InspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "装修巡查管理")
@RestController
@RequestMapping("/inspection")
@AllArgsConstructor
@Validated
public class InspectionController {
    @Autowired
    private InspectionService inspectionService;


    @ApiOperation("列表")
    @GetMapping("/page")
    public CustomPage<InspectionVo> getPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                            @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                            @ApiParam("小区id") @RequestParam(value = "villageId", required = false) Integer villageId,
                                            @ApiParam("楼栋") @RequestParam(value = "building", required = false) Integer building,
                                            @ApiParam("单元") @RequestParam(value = "unit", required = false) Integer unit,
                                            @ApiParam("房号") @RequestParam(value = "roomNumber", required = false) String roomNumber,
                                            @ApiParam("开始时间") @RequestParam(value = "startTime", required = false) String startTime,
                                            @ApiParam("结束时间") @RequestParam(value = "endTime", required = false) String endTime){
        return inspectionService.page(pageNo,pageSize,villageId, building, unit, roomNumber, startTime,endTime);
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(
                    @ApiParam("巡查时间")@RequestParam(value = "time")@NotNull(message = "巡查时间不能为空") LocalDate time,
                    @ApiParam("巡查人员 多人用、隔开")@RequestParam(value = "name")@NotBlank(message = "业主不能为空") String name,
                    @ApiParam("备注")@RequestParam(value = "remarks",required = false) String  remarks,
                    @ApiParam("楼栋id")@RequestParam(value = "buildingId")@NotNull(message = "楼栋id不能为空") Integer buildingId)
    {
        inspectionService.add(buildingId,name,time,remarks);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @ApiParam("巡查时间")@RequestParam(value = "time")@NotNull(message = "巡查时间不能为空") LocalDate time,
                       @ApiParam("巡查人员 多人用、隔开")@RequestParam(value = "name")@NotBlank(message = "业主不能为空") String name,
                       @ApiParam("备注")@RequestParam(value = "remarks",required = false) String  remarks,
                       @ApiParam("楼栋id")@RequestParam(value = "buildingId")@NotNull(message = "楼栋id不能为空") Integer buildingId ){
       inspectionService.update(id,buildingId,name,time,remarks);
    }
    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("编号") @RequestParam("id") @NotNull(message = "编号为空") Integer id){
        inspectionService.delete(id);
    }
}
